<!-- @author benjamin_5 @date 2022/12/4-->


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆</title>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
</head>
<body>

<div>
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-inline">
            <input type="text" name="userName" id="userName" required lay-verify="required" placeholder="请输入账号" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码框</label>
        <div class="layui-input-inline">
            <input type="password" name="password" id="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="checkLogin()">立即提交</button>
        </div>
    </div>
</div>

<script src="../layui/layui.js"></script>
<script src="../js/jQuery3.6.1.js"></script>
<script>

    function checkLogin(){
        $.ajax({
            url: "/user/check",
            data: {
                "userName": $("#userName").val(),
                "password": $("#password").val()
            },
            type: "POST",
            // contentType: 'application/json;charset=UTF-8',
            contentType: 'application/x-www-form-urlencoded',
            cache: "false",
            async:false,
            dataType: "text", // json
            success: function (data) {
                console.log("校验结果",data);
                if(data === "登陆成功"){
                    alert(data);
                }else{
                    alert(data);
                }
            },
            error: function (data) {
                console.log("报错",data);
                alert(data.responseText);
            }
        });
    }
</script>


</body>
</html>